We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

PhalconPHP $this->view->pick issue / bug (maybe)

Strange issue in a controller I have the following IndexAction

    public function indexAction()
    {
        echo "before";
        $this->view->pick('helloworld');
        echo "after";
    }

Just messing around really, but I would expect to see both before and after. Is there a reason I am not seeing the before or after? (I assume output buffering has something to do with this).

I am using a mixture of the Volt & PHP rendering engine using the following custom compilation folder (which I would not expect would influence views...

    //
    // Setup Template Engine(s)
    //
    $di->set( 'view', function() {
        $view = new View();
        $view->setViewsDir( PRIVATEDIR . '/views/' );
        $volt = function($view, $di) {
            $volt = new Volt($view, $di);
            $volt->setOptions( [
                'compiledPath'      =>  function( $templatepath ) {
                    return TMPDIR . '/cache/templates/' . md5( $templatepath ) . '.compiled';
                },
            ] );
            return $volt;
        };

        $view->registerEngines( [
            ".volt"     =>  $volt,
            ".tmpl"     =>  $volt,
            ".phtml"    =>  $volt,
            '.php'      =>  'Phalcon\Mvc\View\Engine\Php',
        ] );
        return $view;
    } );

Update: So strange, but I can echo content before and after initializing phalcon, and it has issues. Framework is Phalcon v2 from apt-get install on Ubuntu 14.04 LTS all updates via PHP5-FPM served through nginx

You may not have told the controller where to show the content from the View. As a side note using flash is a nice way to display content from controller.

In the view do you have:


<?php echo $this->view->getContent(); ?> 

Or if Volt


{{ content() }}

When you are rendering a view, Phalcon won't show the echos or dumps that you do in the controller.

Try to do the same echos with this line before:

$this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_NO_RENDER);

If you can then see the echos, maybe you can play around with the render levels.

Thanks,

To be honest it wasn't hugely important, and I recognise that kind of nasty echo'ing etc can cause issues, I just wondered if it were a bug as I don't remember reading that is how it is supposed to operate anywhere in the docs.

When you are rendering a view, Phalcon won't show the echos or dumps that you do in the controller.

Try to do the same echos with this line before:

$this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_NO_RENDER);

If you can then see the echos, maybe you can play around with the render levels.